<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style>
        .box{
            margin-top:20px;
            margin-bottom:10px;
        }
        .required_text{
            color:red;
            padding: 8px;
        }
    </style>
</head>
<body>

<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <!--行程-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2>2、产品信息配置</h2>
                </div>
                <div class="layui-card-body">
                    <div class="box">
                        <div style="margin-left:20px;">
                            <form class="layui-form" id="trip">
                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span class="required_text">*</span>产品名称</label>
                                    <div class="layui-input-inline" style="width: 400px">
                                        <select id="addTrip" name="trip_id" lay-verify="required" lay-filter="addTrip" lay-search>
                                            <option value="">请填写产品名称</option>
                                            {if !empty($tripArr)}
                                            <option value="{$tripArr.id}" selected="selected">{$tripArr.name}</option>
                                            {/if}
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">起始城市</label>
                                    <div class="layui-input-inline" style="width: 400px">
                                        <select name="startCityId" lay-filter="startCityId" lay-search>
                                            <option value="">请选择城市</option>
                                            {notempty name="$city"}
                                            {volist name="$city" id="vo"}
                                            <option {notempty name='$tripData.startCityId'}{if $vo.id==$tripData.startCityId} selected{/if}{/notempty} value="{$vo.id}">{$vo.name}({$vo.eng_name})</option>
                                            {/volist}
                                            {/notempty}
                                        </select>
                                    </div>
                                </div>

                                <!--<div class="layui-form-item">-->
                                    <!--<label class="layui-form-label">售卖截止天数</label>-->
                                    <!--<div class="layui-input-inline" style="width: 150px">-->
                                        <!--<input name="endDays" {notempty name="$tripData"}value="{$tripData.endDays}"{/notempty} placeholder="请输入数字" autocomplete="off" class="layui-input" type="number">-->
                                    <!--</div>-->
                                <!--</div>-->

                                <div class="layui-form-item layui-form-text" style="position: relative ;z-index: 98;">
                                    <label class="layui-form-label">行程介绍</label>
                                    <div class="layui-input-block" style="max-width:500px;">
                                        <textarea placeholder="此处主要描述客户行程路线计划，对客户和服务伙伴可见，不要放敏感信息。" style="height:300px;" id="toursLineTitle" class="layui-textarea" name="toursLineTitle">{notempty name="$tripData.toursLineTitle"}{$tripData.toursLineTitle}{/notempty}</textarea>
                                    </div>
                                </div>

                                <div class="layui-form-item layui-form-text" style="position: relative ;z-index: 98">
                                    <label class="layui-form-label">特殊说明</label>
                                    <div class="layui-input-block" style="max-width:500px;">
                                        <textarea placeholder="特殊说明： 给司导的特殊提示信息，客户不可见。参考内容：客户对气味比较敏感，车里不能有异味。" class="layui-textarea" name="specialInfo">{notempty name="$tripData.specialInfo"}{$tripData.specialInfo}{/notempty}</textarea>
                                    </div>
                                </div>

                                <input type="hidden" name="page_index" value="3">
                                <input type="hidden" class="standard_id" name="id" {notempty name='$info'}value="{$info.id}"{/notempty}>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-radius" id="title_prev">上一页</button>
                                        <button class="layui-btn layui-btn-radius" lay-submit lay-filter="trip">下一页</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    layui.use(['element','layer', 'form'], function() {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;
        //***************************************************************************
        //产品信息提交
        form.on('submit(trip)', function() {
            $.ajax({
                url:"{:url('admin/standard/submitTripData')}",
                data:$('#trip').serialize(),
                type:'post',
                async: false,
                success:function(res) {
                    console.log(res);
                    layer.msg(res.msg);
                    if(res.code == 1) {
                        setTimeout(function(){
                            location.href = "{:url('admin/standard/savebasic',['id'=>$info.id])}";
                        },1500);
                    }
                    return false;
                }
            });
            return false;
        });

        //模糊查询行程list
        var cpLock2 = true;
        function bindFunc2(){
            //解决监听输入时中文输入法问题
            $("#addTrip").parent().find(".layui-select-title input").on('compositionstart', function () {
                cpLock2 = false;
            });
            $("#addTrip").parent().find(".layui-select-title input").on('compositionend', function () {
                cpLock2 = true;
            });
            $("#addTrip").parent().find(".layui-select-title input").bind('input propertychange',function(){
                var TripName = $(this).val();
                showTripList(TripName);
            });
            //点击时选中文本
            $("#addTrip").parent().find(".layui-select-title input").attr("onfocus","this.select()");
        }
        bindFunc2();
        function showTripList(TripName){
            setTimeout(function(){
                if (cpLock2) {
                    var html="<option value=''>请填写行程名称</option>";
                    $.ajax({
                        url:"{:url('admin/standard/showTripList')}",
                        data:{'TripName':TripName},
                        type:'post',
                        async: false,
                        success:function(data) {
                            console.log(data);
                            for(var i=0;i<data.length;i++){
                                html += "<option value="+data[i]["id"]+" city-id='"+data[i]["start_city"]+"'>"+data[i]["id"]+"__"+data[i]["name"]+"</option>";
                            }
                            $("#addTrip").html(html);
                        }
                    });

                    //重新渲染select
                    form.render('select');
                    bindFunc2();

                    $("#addTrip").next().addClass("layui-form-selected");
                    $("#addTrip").next().find(".layui-input").focus();
                    $("#addTrip").next().find(".layui-input").val(TripName);
                }
            },1);
        }

        //获取行程简介
        function setTripSummary(trip_id){
            $summary = "";
            if(trip_id!="" && trip!=0 && trip!=undefined){
                $.post("/admin/standard/getTripSummary",{trip_id:trip_id},function(data){
                    console.log(data);
                    if(data.code==1){
                        $("textarea[name=toursLineTitle]").val(data.data.title);
                        if(data.data.city!=null && data.data.city > 0){
                            $("select[name=startCityId]").val(data.data.city);
                            form.render("select");
                            bindFunc2();
                        }
                    }
                },"json")
            }

            return $summary;
        }

        //点击行程获取行程简介
        form.on('select(addTrip)',function(data){
            var trip_id = data.value;
            if(trip_id=="" || trip_id==0 || trip_id==undefined){
                return false;
            }else{
                setTripSummary(trip_id);
            }
        });

        //上一页   标题页
        $("#title_prev").click(function(){
            location.href = "{:url('admin/standard/add',['id'=>$info.id])}";
            return false;
        });

    });
</script>

</body>
</html>
